//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing
{
    public class NonVisualPictureProperties : IOfficeXmlSerializable
    {
        private PictureLocking picLocks;
        private bool preferRelativeResize;

        public bool PreferRelativeResize
        {
            get { return preferRelativeResize; }
            set { preferRelativeResize = value; }
        }

        public PictureLocking PictureLocking
        {
            get { return picLocks; }
            set { picLocks = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.ReadAndSwitch("cNvPicPr", DrawingConstants.DrawingNamespaceUri, false))
            {
                PreferRelativeResize = c.GetOptionalBoolean("preferRelativeResize", true);
                PictureLocking = c.ReadOptionalElement<PictureLocking>("picLocks");
                c.WarnIf("relativeResize");
                c.WarnIf("ext");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.WriteAndSwitch("cNvPicPr", DrawingConstants.DrawingNamespace))
            {
                c.SetOptionalBoolean("preferRelativeResize", PreferRelativeResize, true);
                c.WriteOptionalElement(PictureLocking);
                c.WarnIf("relativeResize");
                c.WarnIf("ext");
            }
        }

        #endregion
    }
}